<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>窗口 <span id="status">关闭</span>状态</p>
    <button onclick="openWin()">打开窗口</button>
    <button onclick="closeWin()">关闭窗口</button>
    <br>
    <button onclick="openAlert()">打开alert</button>
    <button onclick="openConfirm()">打开confirm</button>
    <button onclick="openPrompt()">打开prompt</button>
    <br>
    <button onclick="winResizeBy()">winResizeBy</button>
    <button onclick="winResizeTo()">winResizeTo</button>
    <button onclick="winMoveBy()">winMoveBy</button>
    <button onclick="winMoveTo()">winMoveTo</button>
    <button onclick="printWin()">printWin</button>

    <script>
        // 当前页面的父级页面，操作父级页面改变
        window.parent
            // 当前页面的最顶级页面，操作顶级页面改变
        window.top

        function winResizeBy() {
            win.resizeBy(50, 50)

        }

        function winResizeTo() {
            win.resizeTo(400, 400)
        }

        function winMoveBy() {
            win.moveBy(50, 50)
        }

        function winMoveTo() {
            win.moveTo(50, 50)
        }

        function printWin() {
            window.print()
        }

        function openAlert() {
            window.alert('你吃了嘛')
        }

        function openConfirm() {
            var c = window.confirm('你是女性嘛');
            document.write(c ? '我是女性' : '我是男性')
        }

        function openPrompt() {
            var num1 = Number(window.prompt('请填第一个数字')),
                num2 = Number(window.prompt('请填第二个数字'));
            console.log(num1 + num2);

        }


        // closed 窗口是否打开
        var win,
            oStatus = document.getElementById('status');

        function openWin() {
            win = window.open('', '', 'width=500,height=500');
            checkStatus();
        }

        function closeWin() {
            win.close();
            checkStatus();
        }

        function checkStatus() {
            if (win.closed) {
                oStatus.innerHTML = '关闭'
            } else {
                oStatus.innerHTML = '打开'
            }
        }
    </script>
</body>

</html>